<?php

/**
 * @property CI_Loader $load
 * @property CI_Form_validation $form_validation
 * @property CI_Input $input
 * @property CI_Email $email
 * @property CI_DB_active_record $db
 *
 */
class Admin extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper('form');
    }

    function index($failed=0) {
        $data["title"] = "Admin Login";
        $data["content"] = "admin/content";
        $data["sidebar"] = "admin/sidebar";
        $js[] = "admin.js";
        $js[] = "jquery.validate.js";
        $data["js"] = $js;
        if ($failed == 1)
            $data["failed"] = "set";
        $this->load->view('template', $data);
    }

    function admin_login() {
        $this->load->model("Employee");
        $rank = $this->input->post('rank');
        $id = $this->input->post('id');
        $password = $this->input->post('password');
        if ($this->Employee->login($id, $password, $rank)) {
            $newdata = array(
                'id' => $id,
                'rank' => $rank,
                'logged_in' => TRUE
            );

            $this->session->set_userdata($newdata);
            if ($rank == 'SDE')
                redirect('sde');
            else if ($rank == 'DE')
                redirect('de');
            else
                redirect('statistics');
        }
        else {
            redirect('admin/index/1');
        }
    }

}

?>
